home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gold Medal Software 5
/
Gold Medal Software - Volume 5 (Gold Medal) (1995).iso
/
windows
/
win31
/
cenviw.arj
/
MENUCTRL.LIB
< prev
next >
Wrap
Text File
|
1994-03-08
|
9KB
|
229 lines
// MenuCtrl.lib - Functions for controlling window menus.
// ver.1
//
//**** MenuCommand(): Send a menu command to window
// SYNTAX: int MenuCommand(int WindowHandle,int MenuItem[,bool Post])
// int MenuCommand(int WindowHandle,string MenuItem[,bool Post])
// WHERE: WindowHandle: Handle of frame window, if 0 or not supplied
// default to active window
// MenuItem: if integer then it is the menu ID for this item, if string
// then will search through menu items for string with case
// insensitive match to start of string and ignoring the
// '&' character
// Post: Optional, True to PostMessage(), else SendMessage(); default False
// RETURN: Return value of the SendMessage() or PostMessage() call
// NOTE: This function does not report back the MenuItem was not found, but
// only returns FALSE in that case. If you want to be sure about
// finding the item then use GetMenu() and FindMenuString() first.
//
//
//**** SystemMenuCommand(): Send a menu command to window
// SYNTAX: bool SystemMenuCommand(int WindowHandle,int MenuItem[,bool Post])
// bool SystemMenuCommand(int WindowHandle,string MenuItem[,bool Post])
// WHERE: WindowHandle: Handle of frame window, if 0 or not supplied
// default to active window
// MenuItem: if integer then it is the menu ID for this item, if string
// then will search through menu items for string with case
// insensitive match to start of string and ignoring the
// '&' character
// Post: Optional, True to PostMessage(), else SendMessage(); default False
// RETURN: Return value of the SendMessage() or PostMessage() call
// NOTE: See MenuCommand().
//
//
//**** FindMenuString(): Among menus and submenus, find ID for string
// SYNTAX: int FindMenuString(int MenuHandle,string PartialString)
// WHERE: MenuHandle: as retrieved by GetMenu()
// PartialString: string to match menu (case-insensitive) up up to length
// of this string
// RETURN: 0 if not found, else ID of matching menu item
// NOTE: This compares menu item string without the special & character, and
// so this is not very fast
//
//
//**** GetMenu(): Retrieve handle to menu of window
// SYNTAX: int GetMenu([int WindowHandle])
// WHERE: WindowHandle: Handle of frame window, if 0 or not supplied
// default to active window
// RETURN: Return handle to menu for this window, or NULL if no menu
// NOTE: If WindowHandle is a child window then return value is undefined
//
//
//**** GetSystemMenu(): Retrieve handle for system menu
// SYNTAX: int GetMenu([int WindowHandle])
// WHERE: WindowHandle: Handle of frame window, if 0 or not supplied
// default to active window
// RETURN: Return handle to menu for this window, or NULL if no menu
// NOTE: If WindowHandle is a child window then return value is undefined
//
//
//**** GetMenuString(): Get string of a menu item
// SYNTAX: string GetMenuString(int MenuHandle,int id,int Flag)
// WHERE: MenuHandle: as retrieved by GetMenu()
// id: integer ID of menu item, or offset depending on Flag
// Flag: indicate use of id; one of the following
#define MF_BYCOMMAND 0x0000 // use the item ID
#define MF_BYPOSITION 0x0400 // zero-based position
// RETURN: Return string for this menu item, will not be NULL but may be ""
//
//
//**** GetMenuItemID(): Get Menu item ID based on ordinal position
// SYNTAX: int GetMenuItemID(int MenuHandle,int Pos)
// WHERE: MenuHandle: as retrieved by GetMenu()
// Pos: ordinal position of this menu item
// RETURN: Return item ID, or -1 if MenuHandle is 0 or the specified
// item is a pop-up menu item
//
//
//**** GetMenuItemCount()
// SYNTAX: int GetMenuItemCount(int MenuHandle)
// WHERE: MenuHandle: as retrieved by GetMenu()
// RETURN: Return number of items in menu; -1 if error
//
//
//**** GetSubMenu()
// SYNTAX: int GetSubMenu(int MenuHandle,int Pos)
// WHERE: MenuHandle: as retrieved by GetMenu()
// Pos: Ordinal position in parent menu
// RETURN: Return menu handle or NULL
//
//
//**** GetMenuState()
// SYNTAX: int GetMenuState(int MenuHandle,int ItemID,int Flags)
// WHERE: MenuHandle: as retrieved by GetMenu()
// ItemID: menu-item by ordinal or ID depending on Flags containing
// MF_BYPOSITION or MF_BYCOMMAND (see GetMenuString())
// Flag: indicate use of ItemID, ordinal or ID (see GetMenuString())
// RETURN: -1 if item does not exist. If ItemID by position is a sub-menu
// item, then returns number of menu items in high-order byte and
// following flags in low order; else if menu item then returns flags
// integer which is Boolean OR of these values:
#define MF_BITMAP 0x04 // item is a bitmap
#define MF_CHECKED 0x08 // checkmark is next to item
#define MF_DISABLED 0x02 // Item is disabled
#define MF_GRAYED 0x01 // Item is disabled and grayed
#define MF_POPUP 0x10 // popup menu item
#define MF_MENUBREAK 0x40 // new line or new column sith separator
#define MF_MENUBARBREAK 0x20 // same as MF_MENUBREAK with vertical line for popup menus
#define MF_HILITE 0x80 // hilite menu item
#define MF_SEPARATOR 0x800 // Horizontal dividing line in popup menu
//
//
#include <Message.lib>
_GetActiveWindow()
{
return DynamicLink("USER","GETACTIVEWINDOW",SWORD16,PASCAL);
}
GetMenu(pWindowHandle)
{
return DynamicLink( "USER","GETMENU",UWORD16,PASCAL,
va_arg() && pWindowHandle ? pWindowHandle : _GetActiveWindow() );
}
GetSystemMenu(pWindowHandle)
{
return DynamicLink( "USER","GETSYSTEMMENU",UWORD16,PASCAL,
va_arg() && pWindowHandle ? pWindowHandle : _GetActiveWindow(), 0 );
}
GetMenuItemCount(pMenu)
{
return DynamicLink("USER","GETMENUITEMCOUNT",UWORD16,PASCAL,pMenu);
}
GetMenuString(pMenu,pID,pFlag)
{
lString[400] = '\0';
lString[DynamicLink("USER","GETMENUSTRING",SWORD16,PASCAL,pMenu,pID,lString,399,pFlag)] = 0;
return lString;
}
GetMenuState(pMenu,pItemID,pFlags)
{
lRet = DynamicLink("USER","GETMENUSTATE",UWORD16,PASCAL,pMenu,pItemID,pFlags);
if ( 0xFFFF == (lRet & 0xFFFF) )
return -1;
return lRet;
}
GetMenuItemID(pMenu,pPos)
{
lID = DynamicLink("USER","GETMENUITEMID",UWORD16,PASCAL,pMenu,pPos)
return ( 0xFFFF == (lID & 0xFFFF) ) ? -1 : lID ;
}
GetSubMenu(pMenu,pPos)
{
return DynamicLink("USER","GETSUBMENU",UWORD16,PASCAL,pMenu,pPos);
}
MenuMenuCommand(pHwnd,pMenu,pItem,pPost,pMessage)
{
if ( 0 == DataDimension(pItem) ) {
// EASY! Just send item message
lItem = pItem;
} else {
// pItem is a string, so must check all menus items and submenus to find
// pItem
lItem = FindMenuString(pMenu,pItem);
}
if ( !lItem )
return FALSE;
return ( pPost )
? PostMessage(pHwnd,pMessage,lItem,0)
: SendMessage(pHwnd,pMessage,lItem,0) ;
}
MenuCommand(pWindowHandle,pItem,pPost,pMesssage)
{
lPost = ( va_arg() < 3 ) ? False : pPost ;
lHwnd = ( pWindowHandle ) ? pWindowHandle : _GetActiveWindow();
return ( lHwnd && (lMenu = GetMenu(lHwnd)) )
? MenuMenuCommand(lHwnd,lMenu,pItem,lPost,WM_COMMAND)
: FALSE ;
}
SystemMenuCommand(pWindowHandle,pItem,pPost)
{
lPost = ( va_arg() < 3 ) ? False : pPost ;
lHwnd = ( pWindowHandle ) ? pWindowHandle : _GetActiveWindow();
return ( lHwnd && (lMenu = GetSystemMenu(lHwnd)) )
? MenuMenuCommand(lHwnd,lMenu,pItem,lPost,WM_SYSCOMMAND)
: FALSE ;
}
FindMenuString(pMenu,pPartialString)
{
lPartialLen = strlen(pPartialString);
if ( -1 == (lCount = GetMenuItemCount(pMenu)) )
return 0;
for ( lOrd = 0; lOrd < lCount; lOrd++ ) {
if ( -1 == (lMenuID = GetMenuItemID(pMenu,lOrd)) ) {
// this is a submenu, so check down this submenu
if ( (lSubMenu = GetSubMenu(pMenu,lOrd)) ) {
if ( lMenuID = FindMenuString(lSubMenu,pPartialString) )
return lMenuID;
}
} else {
// get string for this item, and compare against partial string with all '&'
lMenuString = GetMenuString(pMenu,lOrd,MF_BYPOSITION);
if ( lMenuString[0] ) {
// remove all '&' characters
lFindAmper = lMenuString;
while ( lFindAmper = strchr(lFindAmper,'&') )
strcpy(lFindAmper,lFindAmper+1);
// compare new found string against our source
if ( !strnicmp(lMenuString,pPartialString,lPartialLen) ) {
// YEA!!!! it is found
return GetMenuItemID(pMenu,lOrd);
}
}
}
}
return 0;
}